package com.caius.xiaohashu.comment.biz.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author Caius
 * @description 热度计算
 * @since Created in 2025-06-06
 */
public class HeatCalculator {
    // 热度计算加权值
    public static final double LIKE_WEIGHT = 0.7; // 点赞加权 0.7
    public static final double REPLY_WEIGHT = 0.3; // 回复加权 0.3

    public static BigDecimal calculateHeat(long likeCount, long replyCount) {
        BigDecimal likeWeight = new BigDecimal(LIKE_WEIGHT);
        BigDecimal replyWeight = new BigDecimal(REPLY_WEIGHT);

        BigDecimal likeCountDB = new BigDecimal(likeCount);
        BigDecimal replyCountDB = new BigDecimal(replyCount);

        BigDecimal heat = likeCountDB.multiply(likeWeight).add(replyCountDB.multiply(replyWeight));

        // 保留两位小数
        return heat.setScale(2, RoundingMode.HALF_UP);
    }

}
